#include <Eigen/Dense>
#include <iostream>
using namespace std;
using namespace Eigen;
int main() {
  Matrix3d A;
  A << 1, 2, 1, 1, 2, 1, -1, 1, 2;
  A(0, 0) = 10;
  A(2, 2) = 20;
  //   A(3,3) = 30;
  Vector3d vec;
  vec << 1, 2, 3;
  cout << "Here is the matrix A:\n" << A << endl;
  cout << "The determinant of A is " << A.determinant() << endl;
  cout << "The inverse of A is:\n" << A.inverse() << endl;
  cout << (4.0 / 2 / 2) << endl;
  cout << A * vec << endl;

  Matrix<double, 6, 6> mat;
  mat << -1, 8, -1, 0, 0, 0, -8, 0, 8, -1, 0, 0, 1, -8, 0, 8, -1, 0, 0, 1, -8,
      0, 8, -1, 0, 0, 1, -8, 0, 8, 0, 0, 0, 1, -8, 0;
  Matrix<double, 4, 4> mat2;

  mat2 << 0, 1, 0, 0, -1, 0, 1, 0, 0, -1, 0, 1, 0, 0, -1, 0;
  Vector4d vec1;
  vec1 << 1, 2, 3, 4;
  cout << mat2.colPivHouseholderQr().solve(vec1);
  cout << mat2.inverse() << endl;

  Matrix<double, 4, 4> mat3;
  double tmp = 1.0 / 6;
  mat3 << -1, 0, 1, 2, 1, 1, 1, 1, 0.5, 0, 0.5, 2, 0, 0, 0, 0;
  mat3(3, 0) = -tmp;
  mat3(3, 1) = 0;
  mat3(3, 2) = tmp;
  mat3(3, 3) = 8 * tmp;
  Vector4d vec2;
  vec2 << 1, 0, 0, 0;
  cout << mat3.colPivHouseholderQr().solve(vec2) << endl;
  //   mat = 0.0;

  MatrixXd mat4 = MatrixXd::Zero(6, 6);

  mat4(0, 0) = -3;
  mat4(0, 1) = 6;
  mat4(0, 2) = -1;

  for (int j = 1; j < 4; ++j) {
    mat4(j, j - 1) = -2;
    mat4(j, j) = -3;
    mat4(j, j + 1) = 6;
    mat4(j, j + 2) = -1;
  }

  mat4(4, 3) = -2;
  mat4(4, 4) = -3;
  mat4(4, 5) = 6;

  mat4(5, 4) = -2;
  mat4(5, 5) = -3;

  cout << "mat4 = " << mat4 << endl;
  cout << "mat4 = " << mat4 << endl;
  cout << mat4.inverse() << endl;

  return 0;
}